using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace RSSRadio.Model
{
    /// <summary>
    /// This is used in ISubscriptionUpdateListener to indicate episode state
    /// </summary>
    public enum EpisodeState
    {
        NewEpisode, PendingDownload, DownloadStarted, DownloadComplete, DownloadCancel
    }

	/// <summary>
	/// Interface for Details bean
	/// <seealso cref="Details"/>
	/// </summary>
	public interface IDetails
	{
		string Title { get; set;}
		string Description { get; set;}
		string Date { get; set;}
		Uri Url { get; set;}
	}
	
	/// <summary>
	/// Defines a bean used to store a podcast's title, description, url, and publish date
	/// </summary>
	public class EpisodeDetails : IDetails
	{
        private string title;
        private string description;
        private string date;
        private Uri url;


        /// <summary>Default contructor</summary>
		public EpisodeDetails()
		{
			this.title = "";
			this.description = "";
			this.date = "";
            // workaround for empty uri - using same thing as RSS.Net on error
            this.url = new Uri("gopher://rss-net.sf.net/");
        }


		/// <summary>
		/// Creates a new bean describing a podcast
		/// </summary>
		/// <param name="title">The podcast's title</param>
		/// <param name="desc">Description of the podcast</param>
		/// <param name="date">Date of the podcast</param>
		/// <param name="url">URI of the podcast's feed</param>
		public EpisodeDetails(string title, string desc, string date, Uri url)
		{
			this.title = "";
			this.description = "";
			this.date = "";
            // workaround for empty uri - using same thing as RSS.Net on error
            this.url = new Uri("gopher://rss-net.sf.net/");

			if (title != null) this.title = title;
			if (desc != null)
			{
				desc = StringUtil.StripXmlCDATATags(desc);

				this.description = desc;
			}
			if (date != null) this.date = date;
			if (url != null) this.url = url;
		}

        [XmlAttribute("title")]
        public string Title
		{
			get { return this.title; }
			set { this.title = value; }
		}

        [XmlAttribute("description")]
        public string Description
		{
			get { return this.description; }
			set	{ this.description = value;	}
		}

        [XmlAttribute("date")]
        public string Date
		{
			get { return this.date; }
			set	{ this.date = value; }
		}

        [XmlIgnore()]
        public Uri Url
		{
			get { return this.url; }
			set	{ this.url = value;	}
		}

        public string GetMediaFileName()
		{
			return StringUtil.GetMediaFileName(this.Url.OriginalString);
		}

        [XmlAttribute("url")]
        public string podcastUrl
        {
            get { return this.url.ToString(); }
            set { this.url = new Uri(value); }
        }

        public string ToMobileHTML()
        {
            StringBuilder html = new StringBuilder("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD "
                + "HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
                + "<html><head><title>Episode Details</title><style type=\"text/css\">"
                + "<!-- body { margin: 9px } --> </style></head><body>");

            html.Append(Date);
            html.Append("<br /><br /><strong>");
            html.Append(Title);
            html.Append("</strong><br /><br />");
            html.Append(Description);
            html.Append("</body></html>");

            return html.ToString();
        }

	}
}
